class MyinfoController < ApplicationController
   before_filter :login_required

   def index
      @user = User.find(session['user'])
   end

   verify :method => :post, :only => [:update ], :redirect_to => { :action => :index }

   # Ajaxed
   def update
      begin
        u = User.find(session['user'])
        render(:text=>"demo user can not change anything here :)") and return if u.login == 'demo'
        
        u.update_attributes!(params[:user]) # raise an error
        render(:text => '0')
     rescue Exception=>e
        render(:text=>e.message)
     end
   end
   
   # Ajaxed, special for administration
   def change_reminder
    id = params[:id].to_i
    value = params[:v].to_i
    u = User.find(id)
    render(:text=>"alert('Error: user not found');") and return if not u
    u.mail_reminder = value
    u.save    
    render(:text=>"alert('Changed user id '+ #{id}+'='+#{value});")
   end
   
end
